package guoyuan.szkingdom.android.module_home

import android.app.Application
import android.content.Context
import android.util.Log
import com.google.auto.service.AutoService
import com.gy.depend.lib_common.base.BaseApplication
import com.gy.depend.lib_common.base.app.ApplicationLifecycle
import dagger.hilt.android.HiltAndroidApp
import org.greenrobot.eventbus.EventBus


/**
 * @author: liujie
 * @date: 2021/7/19
 * @description: 主页application
 */
@AutoService(ApplicationLifecycle::class)
@HiltAndroidApp
class AppApplication :BaseApplication(), ApplicationLifecycle {

    override fun onCreate() {
        // 开启EventBusAPT,优化反射效率 当组件作为App运行时需要将添加的Index注释掉 因为找不到对应的类了
        EventBus
            .builder()
//            .addIndex(MainEventIndex())
            .installDefaultEventBus()
        super.onCreate()

    }

    override fun onAttachBaseContextProxy(context: Context) {
    }

    override fun onCreateProxy(application: Application) {
    }

    override fun onTerminateProxy(application: Application) {
    }

    override fun initByFrontDeskProxy(): MutableList<() -> String> {
        val mutableList = mutableListOf<() -> String>()
        mutableList.add { initOneSdk() }
        mutableList.add { initTwoSdk() }
        mutableList.add { initThreeSdk() }
        return mutableList
    }

    override fun initByBackstageProxy() {
        Log.d("BaseApplication", "initDepends: ${initOneSdk()}")
        Log.d("BaseApplication", "initDepends: ${initTwoSdk()}")
        Log.d("BaseApplication", "initDepends: ${initThreeSdk()}")
    }

    private fun initOneSdk(): String{
        return "initOneSdk成功"+Thread.currentThread().name
    }
    private fun initTwoSdk(): String{
        return "initTwoSdk成功"+Thread.currentThread().name
    }
    private fun initThreeSdk(): String{
        return "initThreeSdk成功"+Thread.currentThread().name
    }
}